ParticleSystem ps;

int timeCount = 5;
void setup()
{
  size(900, 700, P2D);
  //setting = new Settings();
  ps = new ParticleSystem(0, new PVector(0,0));
}

void draw()
{
  background(255);

  ps.run();
  
  //espiral
  //ps.rotation = frameCount % width;
  ps.rotation = (frameCount % width)*10; //com fator fica mais estreito
  for(int i = 360; i > 0; i--)
    {
      addParticle(i);
    }
  if (frameCount % timeCount == 0) {
      //addRandomParticle();
      /*
    addLinearParticle(Settings.LEFT);
    addLinearParticle(Settings.RIGHT);
    addLinearParticle(Settings.UP);
    addLinearParticle(Settings.DOWN);

    addLinearParticle(Settings.UP_LEFT);
    addLinearParticle(Settings.UP_RIGHT);
    addLinearParticle(Settings.DOWN_LEFT);
    addLinearParticle(Settings.DOWN_RIGHT);*/
    
  }
}

void addParticle(int i)
{
  Particle p;
  PVector accel = new PVector(cos(radians(i)), sin(radians(i)));
  p = new Particle(ps.origin, accel, new PVector(0, 0), ps.rotation );
  ps.addParticle(p);
}


void addLinearParticle(int dir)
{
  Particle p;
  PVector accel = new PVector(0, 0);
  float f = 0.05;
  switch(dir)
  {
  case Settings.LEFT:
    accel.x = -f;
    break;
  case Settings.RIGHT:
    accel.x = f;
    break;
  case Settings.UP:
    accel.y = -f;
    break;
  case Settings.DOWN: 
    accel.y = f; 
    break;

  case Settings.UP_LEFT:
    accel.y = -f;
    accel.x = -f;
    break;
  case Settings.UP_RIGHT:
    accel.y = -f;
    accel.x = f;
    break;
  case Settings.DOWN_LEFT:
    accel.y = f;
    accel.x = -f;
    break;
  case Settings.DOWN_RIGHT:
    accel.y = f;
    accel.x = f;
    break;
  }

  //p = new Particle(ps.origin, accel, new PVector(0, 0), ps.rotation );
  //ps.addParticle(p);
}


void addRandomParticle()
{
  ps.addParticle();
}



/* CONTROLS
*******************************/

void keyPressed()
{
  if (key == CODED) {
    if (keyCode == UP) {
      timeCount++;
    } 
    else if (keyCode == DOWN) {
      timeCount-= (timeCount > 1) ? 1 : 0;
    }
  }
}

void mouseMoved()
{
  //ps.rotation = (mouseX / (float) width) * 90f;
}
